package com.dzx.design.structural.flyweight;

/**
 * @author dzx
 * @ClassName:
 * @Description: 享元模式： 其实就是用了一层map作为中间缓存
 * @date 2019年08月08日 14:21:39
 */
public class Test {
    private static final String departments[] = {"RD", "QA", "PM"};

    public static void main(String[] args){
     for (int i=0;i<10;i++){
         String department = departments[(int) (Math.random() * departments.length)];
         Manager manager = (Manager) EmployeeFactory.getManager(department);
         manager.report();
     }

        Integer a = Integer.valueOf(100);
        Integer b = 100;

        Integer c = Integer.valueOf(1000);
        Integer d = 1000;

        /**
         *   public static Integer valueOf(int i) {
         *         if (i >= IntegerCache.low && i <= IntegerCache.high)
         *             return IntegerCache.cache[i + (-IntegerCache.low)];
         *         return new Integer(i);
         *     }
         */
        //根据 jdk源码可知道，当valueOf传入的值大于-128 且小于 127 的时候，就会直接从
        //IntegerCache中获取，不需要new一个新的对象
        System.out.println(a == b);
        System.out.println(c == d);
    }
}
